package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists;
import com.sc.nft.admin.request.SelectIncomeListRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.vo.*;
import com.sc.nft.enums.CommodityType;
import com.sc.nft.enums.IncomeTypeEnum;
import com.sc.nft.exception.GlobalException;
import com.sc.nft.service.DaoService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户收益页面控制器
 *
 * @author Tangzehui
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/userIncome")
@Api(tags = "用户收益页面")
public class UserIncomeController {
    private final DaoService daoService;

    @ApiOperation(value = "查询用户收益数据", notes = "查询用户收益数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/selectIncomeList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<List<UserIncomeDetailsVO>> pageIncomeList( @RequestBody SelectIncomeListRequest request) throws GlobalException {
        return PageResult.success(daoService.pageIncomeList(request.getIncomeTypeEnum(), request.getUserTel(), request.getStartDate(), request.getEndDate(), request.getPageNo(), request.getPageSize()));
    }

    @ApiOperation(value = "获取所有收益类型", notes = "获取所有收益类型", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getIncomeTypeList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<Map<String,Object>>> getIncomeTypeList() {
        IncomeTypeEnum[] values = IncomeTypeEnum.values();
        ArrayList<Map<String,Object>> list = Lists.newArrayList();
        for (IncomeTypeEnum value : values) {
            Map<String,Object> map = new HashMap();
            map.put("name", value);
            map.put("description", value.getDescription());
            map.put("code", value.getCode());
            list.add(map);
        }
        return Result.success(list);
    }
}